In Homework 4, we're asked to create a basic form using ASP.NET server controls (text fields, radio button lists, file uploads, etc.).
The form should have two input buttons: Review and Submit. On clicking the review button, the user should be given a numbered list (ordered list) that contains the field name and associated value for each field in the form. On clicking the submit button, the user should be given a message like: "Thank you for submitting the information."
For more information, read the assignment instructions on Blackboard.
Things you'll need to know...
"How do I make something happen when the user clicks on a button?"
Add an onclick attribute to the server control. The attributes value should be the name of the function you would like run upon being clicked.
"How do I list out selected values of checkboxes?"
You must loop (for loop) through all the checkboxes and store which is selected.
string customerHeardAboutUs ="";for(var i =0; i < hearaboutus.Items.Count; i++){if(hearaboutus.Items[i].Selected){
customerHeardAboutUs = customerHeardAboutUs + hearaboutus.Items[i].Text;
customerHeardAboutUs = customerHeardAboutUs +", ";}}
This loops through all the checkboxes and if a checkbox is selected, its value is appended to a string (customerHeardAboutUs).
"How do I add items to a numbered list dynamically?"
You must first add a bulleted list server control to your aspx page. Afterwards you can use the following line of code to add an item to it.
The form should have two input buttons: Review and Submit. On clicking the review button, the user should be given a numbered list (ordered list) that contains the field name and associated value for each field in the form. On clicking the submit button, the user should be given a message like: "Thank you for submitting the information."
For more information, read the assignment instructions on Blackboard.
Things you'll need to know...
"How do I make something happen when the user clicks on a button?"
Add an onclick attribute to the server control. The attributes value should be the name of the function you would like run upon being clicked.
<asp:Button ID="reviewbutton" runat="server" Text="Review" onClick="formReviewButton_Click" />"How do I access form input field values?"
You can access a field's value by calling its name along with the text (or whichever appropriate) method.
To access a text field ("name" is the name of my input field) :
To access a dropdown list's selected item ("state" is the name of my dropdown list):
To access a calendar's selected time ("servicecal" is the name of my calendar):
"How do I list out selected values of checkboxes?"
You must loop (for loop) through all the checkboxes and store which is selected.
This loops through all the checkboxes and if a checkbox is selected, its value is appended to a string (customerHeardAboutUs).
"How do I add items to a numbered list dynamically?"
You must first add a bulleted list server control to your aspx page. Afterwards you can use the following line of code to add an item to it.
"formlist" in this case is the name of my bulleted list control.